<?php
/**
 * 
 *@file articletag.php
 *@author Zhe.Zhou(zhouzhe@haibao.com)
 *@date 2015-4-20 下午8:10:56
 *@brief  
 */
namespace haibao\cms\business;
use \haibao\cms\data\ArticleTag as ArticleTagData;
class ArticleTag extends \haibao\cms\business\Base{
	public static function getAllTags($articleTagFilter,$isGetOne = FALSE){
	    $articleTagData = new ArticleTagData();
	    if($isGetOne){
	        return $articleTagData->getOne($articleTagFilter);
	    }else{
	        return $articleTagData->getAll($articleTagFilter);
	    }
	}

	public static function getTagsByArticleIds($articleIds,$isPrimaiy = false,$inTags=null){
		$articleTags = $tagInfos = $tags = array();
		$articleTagData = new ArticleTagData();
		$articleTags = $articleTagData->getTagsByArticleIds($articleIds,$isPrimaiy,$inTags);
		if($isPrimaiy){
			foreach($articleTags as $data){
				array_push($tags,$data);
			}
		}else{
			foreach($articleTags as $data){
				$tags = array_merge($tags,$data);
			}
		}
		$tags = array_unique($tags);
		$tagData = new \haibao\cms\data\Tag();
		$tagInfos = $tagData->getTagsById($tags);
		if($isPrimaiy){
			foreach($articleTags as $articleId=>$tagId){
				if(isset($tagInfos[$tagId])){
					$tmpArr = array();
					$tmpArr['TagName'] = $tagInfos[$tagId]['TagName'];
					$tmpArr['Url'] = \haibao\cms\business\control\Base::getTagUrl($tagInfos[$tagId]['Url'],$tagInfos[$tagId]['TagType'],$tagInfos[$tagId]['TopId'],$tagId);
					$articleTags[$articleId] = $tmpArr;
				}
			}
		}else{
			foreach($articleTags as $articleId=>$tags){
				foreach($tags as $key=>$tagId){
					if(isset($tagInfos[$tagId])){
						$tmpArr = array();
						$tmpArr['TagName'] = $tagInfos[$tagId]['TagName'];
						$tmpArr['TagId'] = $tagId;
						$tmpArr['TopId'] = $tagInfos[$tagId]['TopId'];
						$tmpArr['Url'] = \haibao\cms\business\control\Base::getTagUrl($tagInfos[$tagId]['Url'],$tagInfos[$tagId]['TagType'],$tagInfos[$tagId]['TopId'],$tagId);
						$articleTags[$articleId][$key] = $tmpArr;
					}
				}

			}
		}

		return $articleTags;
	}

	public static function updateTagTree($tagTreeArr){
		$articleTagData = new ArticleTagData();
		$articleTagData->updateTagTree(array_unique($tagTreeArr));
	}

}